import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
  },
  {
    path: '/user',
    name: 'User',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/user.vue')
  },
  {
    path: '/cart',
    name: 'Cart',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/cart.vue')
  },
  {
    path: '/about',
    name: 'About',
    // beforeEnter: (to, from, next) => {  about 页面独享的守卫
    //   // ...
    // },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  },
    {
    path: '/delit/:id',
    name: 'Delit',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/delit.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


// 注意：路由的拦截一定要写在 实例化路由之后。


// 全局的前置导航守卫
// router.beforeEach((to, from,next) => {
//   // to 你要去哪个页面 from 你是从哪个页面
//   //  console.log(to);
//   //  console.log(from);
//    // 继续往下面执行
//    if(to.path == '/about'){
//      console.log('你不配过去');
//    } else {
//     next()
//    }
  
//   //  console.log(to);
// })


// 全局的后置守卫
// router.afterEach((to, from) => {
//   // to  你要去哪个页面 
//  // from 你是从哪个页面
//   // console.log();
//   // ...
// })



export default router
